<?php
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use think\Db;

class AdminScoreController extends AdminBaseController
{

    public function index() {
      $list = Db::name('score_rewards')->paginate(10);
      $this->assign('list', $list);
      return $this->fetch();
    }

    public function option_save() {
      if (!$this->request->isPost()) {
        return $this->error('Forbidden');
      }

      $param = $this->request->param();
      $post = $param['post'];

      $data = [
        'custom' => $post['custom'],
        'invite_reward' => $post['invite_reward'],
        'introduce' => $post['introduce'],
      ];
      $data = json_encode($data);

      if ($post['add']) {
        Db::name('option')->insert(['autoload' => '1', 'option_name' => 'score', 'option_value' => $data]);
      } else {
        Db::name('option')->where('option_name', 'score')->update(['option_value' => $data]);
      }

      $this->success('保存成功');
    }

    public function add() {
      return $this->fetch();
    }

    public function addForm() {
      if (!$this->request->isPost()) {
        return $this->error('Forbidden');
      }

      $param = $this->request->param();
      $post = $param;

      $table = Db::name('score_rewards')->insert(['picture' => $param['picture'], 'name' => $param['name'], 'score' => $param['score']]);
    }

    public function edit() {

    }

    public function editForm() {

    }

}
